package com.itmentu.listener.dead;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author：http://www.itmentu.com
 * @date： 2021/12/6 11:10
 * @Description：
 ***/
@Component
public class DeadMessageListener {

    /**
     * 消息死信队列路由过来的数据
     */
    @RabbitListener(queues = "general_queue")
    public void listener(String message,Channel channel, Message msg) throws IOException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(simpleDateFormat.format(new Date())+"  DeadMessageListener->监听到的消息是-->"+message);
        channel.basicAck(msg.getMessageProperties().getDeliveryTag(),false);
    }

    /**
     * 消息监听
     */
    //@RabbitListener(queues = "dead_letter_queue")
    //public void deadListener(String message, Channel channel, Message msg) throws IOException {
    //    System.out.println("DeadMessageListener->监听到的消息是-准备执行Nack，让消息进入死信队列-->"+message);
    //    //执行Nack，让消息进入死信队列
    //    channel.basicNack(msg.getMessageProperties().getDeliveryTag(),false,false);
    //}
}
